# -*- coding: utf-8 -*-
# Author: jurrabi <jurrabi@gmail.com>
# URL: http://code.google.com/p/mytvalacarta//
#
# This file is part of myTValacarta.
#
# myTValacarta is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# myTValacarta is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with myTValacarta.  If not, see <http://www.gnu.org/licenses/>.
'''
Created on 22/08/2010
@author: jurrabi
gui.xbmc_plugin General Description 
'''

import xbmcgui

from tools import logger
logger.debug("[gui.xbmc_plugin]Init")


class Renderer(object):
    def __init__(self):
        pass
    
    def addShow(self,show):
        
        listitem = xbmcgui.ListItem(show.title)
        '''        
        listitem = xbmcgui.ListItem( title, iconImage="DefaultFolder.png", thumbnailImage=thumbnail )
    listitem.setInfo( "video", { "Title" : title, "Plot" : plot, "Studio" : canal } )
    #Realzamos un quote sencillo para evitar problemas con títulos unicode
#    title = title.replace("&","%26").replace("+","%2B").replace("%","%25")
    try:
        title = title.encode ("utf-8") #This only aplies to unicode strings. The rest stay as they are.
    except:
        pass
    itemurl = '%s?channel=%s&action=%s&category=%s&title=%s&url=%s&thumbnail=%s&plot=%s&extradata=%s&Serie=%s' % ( sys.argv[ 0 ] , canal , accion , urllib.quote_plus( category ) , urllib.quote_plus(title) , urllib.quote_plus( url ) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( plot ) , urllib.quote_plus( extradata ) , Serie)

    if Serie != "": #Añadimos opción contextual para Añadir la serie completa a la biblioteca
        addSerieCommand = "XBMC.RunPlugin(%s?channel=%s&action=addlist2Library&category=%s&title=%s&url=%s&extradata=%s&Serie=%s)" % ( sys.argv[ 0 ] , canal , urllib.quote_plus( category ) , urllib.quote_plus( title ) , urllib.quote_plus( url ) , urllib.quote_plus( extradata ) , Serie)
        contextCommands.append(("Añadir Serie a Biblioteca",addSerieCommand))
        
    if len (contextCommands) > 0:
        listitem.addContextMenuItems ( contextCommands, replaceItems=False)
    if totalItems == 0:
        xbmcplugin.addDirectoryItem( handle = pluginhandle, url = itemurl , listitem=listitem, isFolder=True)
    else:
        xbmcplugin.addDirectoryItem( handle = pluginhandle, url = itemurl , listitem=listitem, isFolder=True, totalItems=totalItems)
        '''
        
    def Show(self):
        '''
            # Indicar metadatos del plugin para skis (Categorï¿½a y contenido)
    xbmcplugin.setPluginCategory (pluginhandle , category)
    xbmcplugin.setContent (pluginhandle , category) #Estamos usando category como content.

    # Deshabilitar ordenaciï¿½n
    xbmcplugin.addSortMethod (handle=pluginhandle , sortMethod=xbmcplugin.SORT_METHOD_NONE)

    # Finalizar Directorio del Plugin
    xbmcplugin.endOfDirectory( handle=pluginhandle, succeeded=True )

        '''
        pass
    